using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input.Touch;


namespace GameForKids
{

    public class SampleImg : DrawableGameComponent
    {

        // hinh nen
        protected Texture2D Img;
        public bool show { get; set; }
        public void showImg()
        {
            show = true;
        }
        public void hideImg()
        {
            show = false;
        }
        protected Rectangle rect;
        protected Rectangle rectRoot;
        public Point Location
        {
            get { return rect.Location; }
            set { rect.Location = value; }
        }
        float scale =0.3f;
        public SampleImg(Game game, Texture2D img): base(game)
        {
            Img = img;
            rect = Img.Bounds;
            rectRoot = Img.Bounds;
            rect.Width = (int)(rectRoot.Width * scale);
            rect.Height = (int)(rectRoot.Height * scale);
            rect.X = (800 - rect.Width) / 2;
            rect.Y = 430 - rect.Height;
            show = false;
        }
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            if (!show)
            {
                if (scale > 0.3f)
                {
                    scale -= 0.1f;
                    rect.Width = (int)(rectRoot.Width * scale);
                    rect.Height = (int)(rectRoot.Height * scale);
                    rect.X = (800 - rect.Width) / 2;
                    rect.Y = 430 - rect.Height;
                    spriteBatch.Draw(Img, rect, Color.White);
                }
                spriteBatch.Draw(Img, rect, Color.White);
            }
            else
            {
                if (scale < 1.4f)
                {
                    scale += 0.1f;
                    rect.Width = (int)(rectRoot.Width * scale);
                    rect.Height = (int)(rectRoot.Height * scale);
                    rect.X = (800 - rect.Width) / 2;
                    rect.Y = 430 - rect.Height;
                    spriteBatch.Draw(Img, rect, Color.White);
                }
                spriteBatch.Draw(Img, rect, Color.White);
            }
        }
        public bool Contains(Point position)
        {
            return rect.Contains(position);
        }


        public bool Contains(Vector2 position)
        {
            return Contains(new Point((int)position.X, (int)position.Y));
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public void TouchEvent(TouchLocation touch)
        {
            switch (touch.State)
            {
                case TouchLocationState.Pressed:
                    Pressed(touch);
                    break;
            }
        }


        public void Pressed(TouchLocation touch)
        {

            if (Contains(touch.Position))
            {
                if (show)
                    hideImg();
                else
                    showImg();
            }
        }
    }
}
